/**
 * Created by zeoepan on 2015/9/17.
 */

$(function(){
    /** 初始化ajax */
    jQuery.ajaxSetup({
        case:false,
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    /** 显示搜索按钮 */
    $('input[name=org_id]').bind('blur' , function(){
        var invest_name = $(this).val();

        $.ajax({
            type:"get",
            url:searchInvestOrgByOrgName,
            dataType:"json",
            data:{
                'invest_name':invest_name
            },
            success:function(obj){
                if(obj.level === "success"){
                    noty({text:obj.message,type:level ,timeout:600});
                }else{
                    $('.new_org').show();
                }
            },
            error:function(obj){
                var datajson = obj.responseJSON;
                noty({text:datajson.message,type:datajson.level,timeout:800});
            }
        });

    });
    /** end */


    /** 删除 投资人 */
    $('.del').bind('click' , function(){
        var userId  =   $(this).attr('data');
        var tmp     =   $(this);
        $.ajax({
            type: "get",
            url: DelAdminById,
            dataType: "json",
            data: {
                'userId'    : userId
            },
            success: function (obj) {
                if (obj.level === "success") {
                    noty({text:obj.message,type:obj.level,timeout:500});
                    tmp.parents('tr').hide();
                }
            },
            error: function (obj){
                var datajson = obj.responseJSON;
                noty({text:datajson.message,type:datajson.level,timeout:1000});
            }
        });
    });
    /** end */

    /** 编辑行业领域字段 */
    $(document).on('click','.field',function(){
        var tmp     = $(this);
        var userId  = $('input[name=user_id]').val();
        var fieldId = tmp.val();

        if(!tmp.is(':checked')){
            $.ajax({
                type:"get",
                url:delInvestorField,
                dataType:"json",
                data:{
                    'user_id'    :   userId,
                    'field_id'   :   fieldId
                },
                success:function(obj){

                },
                error:function(obj){
                    var datajson = obj.responseJSON;
                    noty({text:datajson.message,type:datajson.level,timeout:1000});
                }
            });
        }

    });
    /** end */

    /** 编辑阶段字段 */
    $(document).on('click','.phase',function(){
        var tmp     = $(this);
        var userId  = $('input[name=user_id]').val();
        var phaseId = tmp.val();

        if(!tmp.is(':checked')){
            $.ajax({
                type:"get",
                url:delInvestorPhase,
                dataType:"json",
                data:{
                    'user_id'    :   userId,
                    'phase_id'   :   phaseId
                },
                success:function(obj){

                },
                error:function(obj){
                    var datajson = obj.responseJSON;
                    noty({text:datajson.message,type:datajson.level,timeout:1000});
                }
            });
        }
    });
    /** end */





});
